﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;


public class Message
{
    private int mid;
    private string face;
    private string email;
    private string name;
    private string title;
    private string content;
    private DateTime addtime;
    private string replycontent;
    private DateTime replytime;
    private int type;


    public int Type
    {
        get { return type; }
        set { type = value; }
    }

    public int Mid
    {
        get { return mid; }
        set { mid = value; }
    }

    public string Face
    {
        get { return face; }
        set { face = value; }
    }

    public string Email
    {
        get { return email; }
        set { email = value; }
    }
    public string Name
    {
        get { return name; }
        set { name = value; }
    }
    public string Title
    {
        get { return title; }
        set { title = value; }
    }


    public string Content
    {
        get { return content; }
        set { content = value; }
    }

    public DateTime Addtime
    {
        get { return addtime; }
        set { addtime = value; }
    }

    public string Replycontent
    {
        get { return replycontent; }
        set { replycontent = value; }
    }

    public DateTime Replytime
    {
        get { return replytime; }
        set { replytime = value; }
    }

    //游客发表留言
    public const string SENDMSG = "insert into message(face,email,name,title,content,addtime,type) values(@face,@email,@name,@title,@content,@addtime,@type)";

    //管理员回复留言
    public const string REPLYMSG = "update message set replycontent=@replycontent,replytime=@replytime where mid=@mid";

    public const string DELMSG = "delete from message where mid=@mid";

    public const string GETALLMSG = "select * from message where replycontent<>''";

    public void SendMsg(Message m)
    {
        SqlHelper.ExecuteNonQuery(SENDMSG,
            new SqlParameter("@face", m.Face),
            new SqlParameter("@email", m.Email),
            new SqlParameter("@name", m.Name),
            new SqlParameter("@title", m.Title),
            new SqlParameter("@content", m.Content),
            new SqlParameter("@addtime", m.Addtime),
            new SqlParameter("@type", m.Type));
    }

    public void ReplyMsg(Message m)
    {
        SqlHelper.ExecuteNonQuery(REPLYMSG,
            new SqlParameter("@replycontent", m.Replycontent),
            new SqlParameter("@replytime", m.Replytime),
            new SqlParameter("@mid", m.Mid));
    }

    public void DelMsg(int mid)
    {
        SqlHelper.ExecuteNonQuery(DELMSG, new SqlParameter("@mid", mid));
    }

    public DataTable GetAllMsg()
    {
        DataTable dt = new DataTable();
        SqlHelper.FillDataTable(GETALLMSG, dt);
        return dt;
    }


}
